package com.wc.alorithm_blue_bridge._思维.Q1374;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;

/**
 * @Author congge
 * @Date 2023/11/5 20:21
 * @description
 */
public class Answer {
    public static void main(String[] args) {
        Input sc = new Input();

        int n = sc.nextInt();
        int C = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        Arrays.sort(array);
        long ans = 0;
        for (int i = 0, j = 0, k = 0; i < n; i++) {
            while (j < n - 1&&array[j] - array[i] < C){
                j++;
                k++;
            }
            while (k < n&&array[k] - array[i] <=C){
                k++;
            }
            if (array[j] - array[i]==C&&array[k-1]-array[i]==C&&k>1){
                ans += (k - j);
            }
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
